#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Grawlix.Services
{
	/// <summary>
	/// Convenience base class for a service object.
	/// </summary>
	/// <typeparam name="T">The type of service represented.</typeparam>
	[Serializable]
	[SuppressMessage("Microsoft.Usage", "CA2240",
		Justification =
			"Not applicable because it is serialized by proxy.")]
	public abstract class ServiceBase<T> :
		PermanentMarshalByRefObject, ISerializable
	{
		/// <summary>
		/// Populates a 
		/// <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
		/// with the data needed to serialize the target object.
		/// </summary>
		/// <param name="info">The 
		/// <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
		/// to populate with data.</param>
		/// <param name="context">The destination (see 
		/// <see cref="T:System.Runtime.Serialization.StreamingContext"/>
		/// ) for this serialization.</param>
		/// <exception cref="T:System.Security.SecurityException">
		/// The caller does not have the required permission.
		/// </exception>
		[SecurityPermission(SecurityAction.LinkDemand,
			Flags = SecurityPermissionFlag.SerializationFormatter)]
		[SuppressMessage("Microsoft.Design", "CA1033",
			Justification =
				"Derived classes should not override the proxies.")]
		[SuppressMessage("Microsoft.Usage", "CA2240",
			Justification =
				"Not applicable because it is serialized by proxy.")]
		void ISerializable.GetObjectData(SerializationInfo info,
		                                 StreamingContext context)
		{
			GameKernelStreamingContext.GetContextKernel(context);
			info.SetType(typeof(ServiceObjectReference<T>));
		}
	}
}